//
//  SuggestViewController.m
//  SXH
//
//  Created by 房 国生 on 15/7/9.
//  Copyright (c) 2015年 lyss. All rights reserved.
//

#import "SuggestViewController.h"
#import "CommonService.h"

@interface SuggestViewController ()
@property (nonatomic, strong) IBOutlet UITextView *textViewContent;
@property (nonatomic, strong) IBOutlet UITextField *textFieldMail;

@end

@implementation SuggestViewController
@synthesize textViewContent, textFieldMail;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [textViewContent.layer setMasksToBounds:YES];
    [textViewContent.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
    [textViewContent.layer setBorderWidth:1.0]; //边框宽度
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 0.77, 0.77, 0.77, 1 });
    [textViewContent.layer setBorderColor:colorref];//边框颜色
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)doSendSuggest:(id)sender {
    
    if (textViewContent.text.length == 0) {
        ALERT_ERR_MSG(@"请先输入您的宝贵建议！");
        return;
    }
    [super showLoadingView:YES];
    
    CommonService *service = [[CommonService alloc] init];
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
                           @"3", @"id",
                           @"1", @"apptype",
                           textViewContent.text, @"content",
                           textFieldMail.text, @"email",
                           @"5", @"star",nil];
    
    [service getNetWorkData:param
                       Path:FEED_BACK
                  Successed:^(id entity) {
                      NSDictionary *dic = (NSDictionary *)entity;
                      NSNumber *numbber_code = [dic valueForKeyPath:@"code"];
                      if ([numbber_code intValue] == 0) {
                          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"建议反馈成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                          alert.tag = 1001;
                          [alert show];
                      } else {
                          ALERT_ERR_MSG(@"建议反馈失败");
                      }
                      [super showLoadingView:NO];
                  } Failed:^(NSInteger errorCode, NSString *message) {
                      [super showLoadingView:NO];
                  }];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if ( alertView.tag == 1001) {
        [self.navigationController popViewControllerAnimated:YES];
        NSLog(@"点击了确认按钮");
    }
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"SuggestViewController"];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"SuggestViewController"];
}
@end
